/**
 * @param {string} s
 * @return {string}
 */
var reverseWords = function (s) {
   let left = s.length - 1
   let right = 0
   let res = []
   while (left >= 0) {
      if (s[left] !== ' ') {
         right = left
         while (left !== ' ' && left >= 0) {
            left--
         }
         res.push(s.slice(left + 1, right + 1))
      }
      left--
   }
   return res.join(' ')
};
console.log(reverseWords("the sky is blue"));